<template>
   <van-goods-action>
    <van-goods-action-icon :icon="ifSave ? 'star' : 'star-o'" :text="ifSave ? '已收藏' : '收藏'" :color="ifSave ? 'darkred' : '#666'" @click="ifSave=!ifSave" />
    <van-goods-action-icon icon="cart-o" text="购物车" @click="gotoCart" class="cartiCon" >
        <div class="goods_count">{{proCount}}</div>
    </van-goods-action-icon>
    <van-goods-action-button type="danger" text="立即购买" @click="buyNow" />
    <van-goods-action-button type="warning" text="加入购物车" @click="addToCart"/>
  </van-goods-action>
</template>

<script>
export default {
    namee:'myGoodsAdd',
    props:['proCount'],
    data() {
        return {
        ifSave: false
        }
    },
    methods: {
        buyNow() {
        this.$toast('您所在地区尚不支持购买')
        },
        // 点击加入购物车
        addToCart() {
        this.$emit('addToCart')
        },
        // 跳转到购物车
        gotoCart() {
        
         let token = localStorage.getItem("userToken");
         if(token){
              this.$router.push('/cart')
         }else{
              this.$toast.loading("正在转跳登录页面");
            setTimeout(() => {
                 this.$router.push('/user') 
            }, 2000)
                   
         }
        }
    }
}
</script>

<style>
.cartiCon{
    position: relative;
    
}
.goods_count{
    position:absolute;
    top:5px;
    right: 8px;
    width: 18px;
    height: 15px;
    background-color: red;
    border-radius: 50%;
    color: #fff;
    line-height: 15px;
    text-align: center;
    font-size: .08rem;
}

</style>